import { Injectable } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
import { WxConfig } from 'app/shared/model/wx-config.model';
import { WxConfigService } from './wx-config.service';
import { WxConfigComponent } from './wx-config.component';
import { WxConfigDetailComponent } from './wx-config-detail.component';
import { WxConfigUpdateComponent } from './wx-config-update.component';
import { IWxConfig } from 'app/shared/model/wx-config.model';

@Injectable({ providedIn: 'root' })
export class WxConfigResolve implements Resolve<IWxConfig> {
    constructor(private service: WxConfigService) {}

    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        const id = route.params['id'] ? route.params['id'] : null;
        if (id) {
            return this.service.find(id).pipe(map((wxConfig: HttpResponse<WxConfig>) => wxConfig.body));
        }
        return of(new WxConfig());
    }
}

export const wxConfigRoute: Routes = [
    {
        path: 'wx-config',
        component: WxConfigComponent,
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'WxConfigs'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'wx-config/:id/view',
        component: WxConfigDetailComponent,
        resolve: {
            wxConfig: WxConfigResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'WxConfigs'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'wx-config/new',
        component: WxConfigUpdateComponent,
        resolve: {
            wxConfig: WxConfigResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'WxConfigs'
        },
        canActivate: [UserRouteAccessService]
    },
    {
        path: 'wx-config/:id/edit',
        component: WxConfigUpdateComponent,
        resolve: {
            wxConfig: WxConfigResolve
        },
        data: {
            authorities: ['ROLE_USER'],
            pageTitle: 'WxConfigs'
        },
        canActivate: [UserRouteAccessService]
    }
];
